package com.ruoyi.system.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.system.domain.ZtfAppMainTables;
import com.ruoyi.system.domain.ZtfMainTables;
import com.ruoyi.system.domain.dto.ZtfAppMainTablesDTO;
import com.ruoyi.system.result.PageResult;
import com.ruoyi.system.service.IZtfAppMainTablesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 智提分考试大师Controller
 * 
 * @author ruoyi
 * @date 2025-05-30
 */
@RestController
@RequestMapping("app/system/course")
@Api(tags = "app课程相关接口")
public class ZtfAppMainTablesController extends BaseController
{
    @Autowired
    private IZtfAppMainTablesService ztfAppMainTablesService;

    /**
     * 查询智提分考试大师列表(系统分页)
     */
//    @PreAuthorize("@ss.hasPermi('system:tables:list')")
    @GetMapping("/list")
    @ApiOperation("系统课程列表接口")
    public TableDataInfo list(ZtfAppMainTables ztfAppMainTables)
    {
//        startPage();
        //获取用户id
       long userId=SecurityUtils.getUserId();
        List<ZtfAppMainTables> list = ztfAppMainTablesService.selectZtfMainTablesList(userId,ztfAppMainTables);
        return getDataTable(list);
    }

    //新的分页方法
    @GetMapping("/newList")
    @ApiOperation("新的课程列表接口")
    public R<PageResult> list(ZtfAppMainTablesDTO ztfAppMainTablesDTO)
    {
       //获取用户id
       long userId =SecurityUtils.getUserId();
        //返回分页数据
        PageResult pageResult  = ztfAppMainTablesService.newSelectZtfMainTablesList(ztfAppMainTablesDTO,userId);
        return R.ok(pageResult);
    }

    /**
     * 导出智提分考试大师列表
     */
//    @PreAuthorize("@ss.hasPermi('system:tables:export')")
//    @Log(title = "智提分考试大师", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, ZtfAppMainTables ztfMainTables)
//    {
//        List<ZtfAppMainTables> list = ztfAppMainTablesService.selectZtfMainTablesList(ztfMainTables);
//        ExcelUtil<ZtfAppMainTables> util = new ExcelUtil<ZtfAppMainTables>(ZtfAppMainTables.class);
//        util.exportExcel(response, list, "智提分考试大师数据");
//    }

    /**
     * 获取智提分考试大师详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:tables:query')")
    @GetMapping(value = "/{ztfid}")
    public AjaxResult getInfo(@PathVariable("ztfid") Long ztfids)
    {
        return success(ztfAppMainTablesService.selectZtfMainTablesByZtfid(ztfids));
    }

    /**
     * 新增智提分考试大师
     */
    @PreAuthorize("@ss.hasPermi('system:tables:add')")
    @Log(title = "智提分考试大师", businessType = BusinessType.INSERT)
    @ApiOperation("课程新增接口")
    @PostMapping
    public AjaxResult add(@RequestBody ZtfMainTables ztfMainTables)
    {

        ztfMainTables.setFastUUID(ztfMainTables.getDictCode());
        String uuid = IdUtils.simpleUUID();
        ztfMainTables.setZtfid(uuid);
        return toAjax(ztfAppMainTablesService.insertZtfMainTables(ztfMainTables));
    }

    /**
     * 修改智提分考试大师
     */
    @PreAuthorize("@ss.hasPermi('system:tables:edit')")
    @Log(title = "智提分考试大师", businessType = BusinessType.UPDATE)
    @PutMapping("/update")
    @ApiOperation("课程修改接口")
    public AjaxResult edit(@RequestBody ZtfMainTables ztfMainTables)
    {
        return toAjax(ztfAppMainTablesService.updateZtfMainTables(ztfMainTables));
    }

    /**
     * 删除智提分考试大师
     */
    @PreAuthorize("@ss.hasPermi('system:tables:remove')")
    @Log(title = "智提分考试大师", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ztfids}")
    @ApiOperation("课程删除接口")
    public AjaxResult remove(@PathVariable("ztfids") String[] ztfids)
    {
        return toAjax(ztfAppMainTablesService.deleteZtfMainTablesByZtfids(ztfids));
    }
}
